*/
-#include <QLatin1String> // for QLatin1String
-#include <QString> // for QString
-#include <QStringView> // for QStringView
-#include <QVector> // for QVector
-#include <QXmlStreamAttribute> // for QXmlStreamAttribute
-#include <QXmlStreamAttributes> // for QXmlStreamAttributes
-#include <Qt> // for CaseInsensitive
-
-#include "defs.h"
-#include "xmlgeneric.h" // for cb_start, cb_end, xg_callback, xg_string, xg_cb_type, xml_deinit, xml_init, xml_read, xg_tag_mapping
-
-static Waypoint* wpt_tmp;
-static int item_count;
-static int waypoints;
-static double version;
-static route_head* route = nullptr;
-
-static char* routevia = nullptr;
-
-static QVector<arglist_t> tef_xml_args = {
- {
- "routevia", &routevia, "Include only via stations in route",
- nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
- },
-};
+#include "tef_xml.h"
-#define MYNAME "TourExchangeFormat"
+#include <QLatin1String> // for QLatin1String
+#include <QString> // for QString, QStringView::toString
+#include <QXmlStreamAttribute> // for QXmlStreamAttribute
+#include <QXmlStreamAttributes> // for QXmlStreamAttributes
+#include <Qt> // for CaseInsensitive
+
+#include <type_traits> // for add_const<>::type
-static xg_callback tef_start, tef_header, tef_list_start, tef_list_end;
-static xg_callback tef_item_start, tef_point, tef_item_end;
+#include "defs.h" // for Waypoint, fatal, wp_flags, route_add_head, route_add_wpt, route_head, waypt_add
+#include "xmlgeneric.h" // for xg_string, build_xg_tag_map, xml_deinit, xml_init, xml_read
-static
-xg_tag_mapping tef_xml_map[] = {
- { tef_start, cb_start, "/TEF" },
- { tef_header, cb_start, "/TEF/Header" },
- { tef_list_start, cb_start, "/TEF/WaypointList" },
- { tef_item_start, cb_start, "/TEF/WaypointList/Item" },
- { tef_point, cb_start, "/TEF/WaypointList/Item/Point" },
- { tef_item_end, cb_end, "/TEF/WaypointList/Item" },
- { tef_list_end, cb_end, "/TEF/WaypointList" },
- { nullptr, (xg_cb_type)0, nullptr }
-};
+#define MYNAME "TourExchangeFormat"
/*
* tef_start: check for comment "TourExchangeFormat"
*/
-static void
-tef_start(xg_string, const QXmlStreamAttributes* attrv)
+void
+TefXMLFormat::tef_start(xg_string /*unused*/, const QXmlStreamAttributes* attrv)
{
bool valid = false;
* tef_header: "Name" > Route name, "Software" > Route descr.
*/
-static void
-tef_header(xg_string, const QXmlStreamAttributes* attrv)
+void
+TefXMLFormat::tef_header(xg_string /*unused*/, const QXmlStreamAttributes* attrv)
{
route = new route_head;
for (const auto& attr : *attrv) {
route_add_head(route);
}
-static void
-tef_list_start(xg_string, const QXmlStreamAttributes* attrv)
+void
+TefXMLFormat::tef_list_start(xg_string /*unused*/, const QXmlStreamAttributes* attrv)
{
if (attrv->hasAttribute("ItemCount")) {
item_count = attrv->value("ItemCount").toString().toUInt();
*/
// FIXME: the calling convention here is screwy. notes is an input AND
// output argument and may be modified.
-static char*
-fix_notes(const char* name, char* notes)
+char*
+TefXMLFormat::fix_notes(const char* name, char* notes)
{
const char* cleft, *cright, *cback;
char* ctmp;
return notes;
}
-static char*
-Xfix_notes(const QString& name, const QString& notes)
+char*
+TefXMLFormat::Xfix_notes(const QString& name, const QString& notes)
{
char* cname = xstrdup(name);
return r;
}
#else
-static QString
-fix_notes(const QString&, const QString& notes){
+QString
+TefXMLFormat::fix_notes(const QString& /*unused*/, const QString& notes){
return notes;
}
#endif
-static void
-waypoint_final()
+void
+TefXMLFormat::waypoint_final()
{
if (wpt_tmp == nullptr) {
return;
wpt_tmp = nullptr;
}
-static void
-tef_item_end(xg_string, const QXmlStreamAttributes*)
+void
+TefXMLFormat::tef_item_end(xg_string /*unused*/, const QXmlStreamAttributes* /*unused*/)
{
waypoint_final();
}
-static void
-tef_list_end(xg_string, const QXmlStreamAttributes*)
+void
+TefXMLFormat::tef_list_end(xg_string /*unused*/, const QXmlStreamAttributes* /*unused*/)
{
waypoint_final();
if (waypoints != item_count)
waypoints, item_count);
}
-static void
-tef_item_start(xg_string, const QXmlStreamAttributes* attrv)
+void
+TefXMLFormat::tef_item_start(xg_string /*unused*/, const QXmlStreamAttributes* attrv)
{
waypoints++;
}
}
-static double
-tef_read_comma_float(QStringView value)
+double
+TefXMLFormat::tef_read_comma_float(QStringView value)
{
QString svalue = value.toString();
return fixed.toDouble();
}
-static void
-tef_point(xg_string, const QXmlStreamAttributes* attrv)
+void
+TefXMLFormat::tef_point(xg_string /*unused*/, const QXmlStreamAttributes* attrv)
{
if (!wpt_tmp) {
return;
}
}
-static void
-tef_xml_rd_init(const QString& fname)
+void
+TefXMLFormat::rd_init(const QString& fname)
{
wpt_tmp = nullptr;
waypoints = 0;
item_count = -1;
version = 1.5;
- xml_init(fname, tef_xml_map, nullptr);
+ xml_init(fname, build_xg_tag_map(this, tef_xml_map), nullptr, nullptr, nullptr, true);
}
-static void
-tef_xml_read()
+void
+TefXMLFormat::read()
{
xml_read();
}
-static void
-tef_xml_rd_deinit()
+void
+TefXMLFormat::rd_deinit()
{
xml_deinit();
}
-
-ff_vecs_t tef_xml_vecs = {
- ff_type_file,
- { ff_cap_none, ff_cap_none, ff_cap_read },
- tef_xml_rd_init,
- nullptr,
- tef_xml_rd_deinit,
- nullptr,
- tef_xml_read,
- nullptr,
- nullptr,
- &tef_xml_args,
- CET_CHARSET_UTF8, 1
- , NULL_POS_OPS,
- nullptr
-};
--- /dev/null
+/*
+ Support for XML based "TourExchangeFormat",
+ found in Map & Guide Motorrad-Tourenplaner 2005/06
+
+ Copyright (C) 2005 Olaf Klein, o.b.klein@gpsbabel.org
+
+ Based on kml.c, Keyhole "kml" format.
+ Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+#ifndef TEF_XML_H_INCLUDED_
+#define TEF_XML_H_INCLUDED_
+
+#include <QList> // for QList
+#include <QString> // for QString
+#include <QStringView> // for QStringView
+#include <QVector> // for QVector
+#include <QXmlStreamAttributes> // for QXmlStreamAttributes
+
+#include "defs.h" // for arglist_t, ff_cap, ff_cap_none, ARGTYPE_BOOL, ARG_NOMINMAX, CET_CHARSET_UTF8, Waypoint, ff_cap_read, ff_type, ff_type_file, route_head
+#include "format.h" // for Format
+#include "xmlgeneric.h" // for xg_functor_map_entry, xg_string, cb_start, cb_end
+
+
+class TefXMLFormat : public Format
+{
+public:
+ QVector<arglist_t>* get_args() override
+ {
+ return &tef_xml_args;
+ }
+
+ ff_type get_type() const override
+ {
+ return ff_type_file;
+ }
+
+ QVector<ff_cap> get_cap() const override
+ {
+ /* waypoints, tracks, routes */
+ return { ff_cap_none, ff_cap_none, ff_cap_read };
+ }
+
+ QString get_encode() const override
+ {
+ return CET_CHARSET_UTF8;
+ }
+
+ int get_fixed_encode() const override
+ {
+ return 1;
+ }
+
+ void rd_init(const QString& fname) override;
+ void read() override;
+ void rd_deinit() override;
+
+private:
+ /* Member Functions */
+
+ static QString fix_notes(const QString& /*unused*/, const QString& notes);
+ void waypoint_final();
+ static double tef_read_comma_float(QStringView value);
+ void tef_start(xg_string /*unused*/, const QXmlStreamAttributes* attrv);
+ void tef_header(xg_string /*unused*/, const QXmlStreamAttributes* attrv);
+ void tef_list_start(xg_string /*unused*/, const QXmlStreamAttributes* attrv);
+ void tef_item_end(xg_string /*unused*/, const QXmlStreamAttributes* /*unused*/);
+ void tef_list_end(xg_string /*unused*/, const QXmlStreamAttributes* /*unused*/);
+ void tef_item_start(xg_string /*unused*/, const QXmlStreamAttributes* attrv);
+ void tef_point(xg_string /*unused*/, const QXmlStreamAttributes* attrv);
+
+ /* Data Members */
+
+ Waypoint* wpt_tmp{};
+ int item_count{};
+ int waypoints{};
+ double version{};
+ route_head* route = nullptr;
+
+ char* routevia = nullptr;
+
+ QVector<arglist_t> tef_xml_args = {
+ {
+ "routevia", &routevia, "Include only via stations in route",
+ nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+ }
+ };
+
+ QList<xg_functor_map_entry<TefXMLFormat>> tef_xml_map = {
+ { &TefXMLFormat::tef_start, cb_start, "/TEF" },
+ { &TefXMLFormat::tef_header, cb_start, "/TEF/Header" },
+ { &TefXMLFormat::tef_list_start, cb_start, "/TEF/WaypointList" },
+ { &TefXMLFormat::tef_item_start, cb_start, "/TEF/WaypointList/Item" },
+ { &TefXMLFormat::tef_point, cb_start, "/TEF/WaypointList/Item/Point" },
+ { &TefXMLFormat::tef_item_end, cb_end, "/TEF/WaypointList/Item" },
+ { &TefXMLFormat::tef_list_end, cb_end, "/TEF/WaypointList" }
+ };
+};
+#endif // TEF_XML_H_INCLUDED_